package demo102.entity.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;



import demo102.dao.StudentDao;
import demo102.entity.Student;
import demo102.util.JdbcUtil;

public class StudentDaoImpo implements StudentDao{
	public List<Student> findAll(){
		List<Student> list = new ArrayList<Student>();
		Connection conn = JdbcUtil.getConnection();
		String sql = "select * from student";
		Statement st;
		try {
			st = conn.createStatement();
			ResultSet rs = st.executeQuery(sql);
			while (rs.next()) {
				int sid = rs.getInt("sid");
				String sname = rs.getString("sname");
				int age = rs.getInt("age");
				Student s = new Student(sid, sname, age);
				list.add(s);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return list;
	}

	@Override
	public int add(Student s) {
		return 0;
	}
}
